<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/15 10:35
 * Note: 系统-首页
 */
//系统-首页
namespace Admin\Controller;
use Think\Controller;
class IndexController extends CommonController {

    public function index(){
        // print_r($_SESSION);die;
        //未登录,则显示登录页
        if(!$_SESSION['SESSION_PREFIX']['adminInfo']){
            $this->redirect("Public/index");
        }

        $info = array(
            'info_00' => $_SERVER['SERVER_NAME'],//域名
            'info_01' => PHP_OS,
            'info_02' => $_SERVER['SERVER_ADDR'],
            'info_03' => $_SERVER['SERVER_SOFTWARE'],
            'info_04' => php_sapi_name(),
        );
//        print_r($info);die();
        $this->assign('title', '后台管理首页');
        $this->assign('info', $info);
        $this->display();
    }
    //系统设置
    public function system(){
        $info = M('System')->where("id=1")->find();
        $info['updatetime'] = date('Y-m-d H:i:s', $info['updatetime']);
        if(IS_POST){
            $url = I('url','','trim');
            $title = I('title','','trim');
            if(empty($url)){
                $this->error('域名不能为空！');
            }
            if(empty($title)){
                $this->error('网站名称不能为空！');
            }
            $data = array(
                'id' => I('id',1,'intval'),
                'url' => $url,
                'title' => $title,
                'keywords' => I('keywords','','trim'),
                'desc' => I('desc','','trim'),
                'updatetime' => time(),
            );
//            print_r($data);die();
            $result = M('System')->save($data);
            if(!$result) {
                $this->error('更新失败！',U('Index/index'));
            }else{
                $this->success('更新成功！',U('Index/index'));
            }
            return;
        }
//        print_r($info);die();
        $this->assign('info', $info);
        $this->assign('title', '系统设置');
        $this->display();
    }

}